//
//  UserHeadView.m
//  TheProjectName
//
//  Created by 李劲成 on 16/5/21.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "UserHeadView.h"

@interface UserHeadView ()

@property (nonatomic, retain) UIImageView *m_photo;

@property (nonatomic, retain) UILabel *name;

@end

@implementation UserHeadView

#pragma mark - 重写初始化
-(instancetype)initWithFrame:(CGRect)frame addTarget:(nonnull id)target action:(nonnull SEL)action
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:target action:action];
        [_m_photo addGestureRecognizer:tap];
     
    }
    return self;
}

- (void)createSubView{
 
    self.m_photo = [[UIImageView alloc]initWithFrame:CGRectMake(FRAME_WIDTH(self) * 0.3, 0, FRAME_WIDTH(self) * 0.4, FRAME_WIDTH(self) * 0.4)];
    _m_photo.userInteractionEnabled = YES;
    // 切圆
    UIImage *image = [UIImage imageNamed:@"1111.jpg"];
    UIGraphicsBeginImageContextWithOptions(_m_photo.bounds.size, NO, 1.0);
    [[UIBezierPath bezierPathWithRoundedRect:_m_photo.bounds cornerRadius:FRAME_WIDTH(self) * 0.2]addClip];
    [image drawInRect:_m_photo.bounds];
    _m_photo.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
     [self addSubview:_m_photo];
  
    
    self.name = [[UILabel alloc]initWithFrame:CGRectMake(FRAME_WIDTH(self) * 0.3, FRAME_WIDTH(self) * 0.4 + 5, FRAME_WIDTH(self) * 0.4, FRAME_HEIGHT(self) - FRAME_WIDTH(self) * 0.4 - 10)];
    _name.text = [EMClient sharedClient].currentUsername;
    _name.font = [UIFont boldSystemFontOfSize:20];
    _name.textColor = [UIColor whiteColor];
    _name.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_name];
}
@end
